/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package fr.p10.miage.gestionabsence.model;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 *
 * @author huynal
 */
public class PromotionBDD {
     
   public PromotionBDD() {
       
   }

   public static Promotion trouverParId(int id) throws SQLException, Exception {
      Promotion promotion = new Promotion();
      String sql = "SELECT * FROM PROMOTION WHERE IDP = ? LIMIT 1";
      PreparedStatement pst = Connection.getBDD().prepareStatement(sql, ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
      pst.setInt(1, id);
      if (pst.execute()) {
            ResultSet resultat = pst.getResultSet();
            if (resultat.first() == true) {
                promotion.init(resultat);
            } else {
                throw new Exception("Promotion inconnu");
            }
            resultat.close();
        }
        return promotion;
   }  
}
